package com.peng.event;

import com.peng.data.WakCommonData;

import javax.swing.undo.UndoManager;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;

/**
 * @author : pengyf
 * @version : 1.0
 * @createTime : 2022/1/22 13:14
 * @Description : Ctrl+z, Ctrl+y 按钮监听，事项撤销和回退
 */
public class CzAndCyKeyListener implements KeyListener {

    @Override
    public void keyTyped(KeyEvent e) {}

    @Override
    public void keyPressed(KeyEvent evt) {
        if (evt.isControlDown() && evt.getKeyCode() == KeyEvent.VK_Z) {
            if (WakCommonData.UNDOMANAGER.canUndo()) {
                WakCommonData.UNDOMANAGER.undo();
            }
        }
        if (evt.isControlDown() && evt.getKeyCode() == KeyEvent.VK_Y) {
            if (WakCommonData.UNDOMANAGER.canRedo()) {
                WakCommonData.UNDOMANAGER.redo();
            }
        }
    }

    @Override
    public void keyReleased(KeyEvent e) {}
}
